package modele;

import librairies.dictionnaire.interfaces.IDonneeDico;

/**
 * Bean d'un mot
 * 
 * @author mlozach
 */
public class Mot implements IDonneeDico<Mot>
{
	private String value;
	private String provenance;
	
	public Mot() 
	{
		this.provenance = null;
		this.value = null;
	}
	
	public Mot(String value, String provenance) 
	{
		this.provenance = provenance;
		this.value = value;
	}

	@Override
	public int compareTo(Mot arg0) 
	{
		if(this.value == null && arg0 == null) return 0;
		if(this.value != null && arg0 == null) return 1;
		if(this.value == null && arg0 != null) return -1;
		
		return this.value.compareToIgnoreCase(arg0.getValue());
	}

	@Override
	public void addition(IDonneeDico<Mot> o) 
	{
		if(o != null) 
		{
			if((o.getProvenance() == null) || (o.getProvenance().equalsIgnoreCase(this.provenance))) 
			{
				this.value.concat(o.getValue());
			}
		}
	}

	@Override
	public boolean contains(Object o) 
	{
		if(o == null) return false;
	
		if(o instanceof Mot) 
		{
			Mot arg = (Mot) o;
			
			if(this.value.contains(arg.getValue())) 
			{
				return true;
			} 
			else 
			{
				return false;
			}
			
		} 
		else if(o instanceof String) 
		{
			String arg = (String) o;
			
			if(this.value.contains(arg))
			{
				return true;
			} 
			else 
			{
				return false;
			}
		}
		else 
		{
			return false;
		}
	}
	
	@Override
	public String toString()
	{
		return this.value;
	}
	
	public String getValeurString()
	{
		if(this.provenance == null) return this.value;
		
		StringBuffer tmp = new StringBuffer();
		tmp.append("value = ");
		tmp.append(this.value);
		tmp.append(", provenance = ");
		tmp.append(this.provenance);
		
		return tmp.toString();
	}
	
	
	public void setValue(String value) {this.value = value;}
	public void setProvenance(String provenance) {this.provenance = provenance;}
	@Override
	public String getValue() {return this.value;}
	@Override
	public String getProvenance() {return this.provenance;}
}
